import 'package:erp_widget/src/theme/index.dart';
import 'package:erp_widget/src/utils/screen/size_extension.dart';
import 'package:flutter/material.dart';

import 'custom.dart';
import 'model.dart';

class DxListPopMenu extends StatelessWidget {
  final bool darkMode;
  final List<DxPopMenuModel> items;
  final DxPopMenuController controller;
  final dynamic data;

  const DxListPopMenu({
    Key? key,
    this.darkMode = true,
    required this.items,
    required this.controller,
    this.data,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DecoratedBox(
      decoration: BoxDecoration(
        color: darkMode ? DxStyle.$404040 : Colors.white,
        borderRadius: BorderRadius.circular(5),
        boxShadow: darkMode ? null : [const BoxShadow(color: Colors.grey, spreadRadius: 1, blurRadius: 5)],
      ),
      child: IntrinsicWidth(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: items
              .map(
                (item) => GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    controller.hideMenu();
                    item.callback?.call(data);
                  },
                  child: Container(
                    height: 50.h,
                    padding: EdgeInsets.symmetric(horizontal: 25.w),
                    decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(color: darkMode ? Colors.white24 : Colors.black12, width: 0.2.w),
                      ),
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Icon(item.icon, size: 18.sp, color: darkMode ? Colors.white : Colors.black),
                        SizedBox(width: 12.w),
                        Expanded(
                          child: Text(
                            item.title,
                            style: TextStyle(color: darkMode ? Colors.white : Colors.black, fontSize: 15.sp),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              )
              .toList(),
        ),
      ),
    );
  }
}
